package com.ts.content.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ts.common.core.utils.Result;
import com.ts.common.security.dto.UserLoginDto;
import com.ts.content.entity.CommentEntity;
import com.ts.content.entity.PostEntity;
import com.ts.content.entity.TopicEntity;
import com.ts.content.service.CommentService;
import com.ts.content.service.PostService;
import com.ts.content.service.TopicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.query.Param;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * 评论表
 *
 * @author 小张@qq.com
 * @since 1.0.0 2023-03-07
 */
@RestController
@RequestMapping("/comment")
public class CommentController {

    @Autowired
    private CommentService commentService;
    @Autowired
    private PostService service;
    /**
     * 添加评论的方法
     */
    @PostMapping("/addComment")
    public void add(@RequestBody CommentEntity commentEntity, UserLoginDto userLoginDto) {
        Integer userId = userLoginDto.getUserId();
        commentEntity.setUserId(userId);
        // 调用业务层的插入方法
        commentService.save(commentEntity);
    }
    /**
     * 查询的评论的方法
     */
    @GetMapping("/list")
     public Result list(
             @Param(value = "postId") Integer postId,
             @Param(value = "page") Integer page){
        // 通过帖子id来查询评论
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("post_id",postId);

        return new Result<>().Viewok(commentService.list(queryWrapper));
     }
}